Skip to content

Ensure PVCs are detached from VM only if VM spec does not have reference to them.#4003

Open
skogta wants to merge 1 commit into
kubernetes-sigs:masterfrom
skogta:topic/skogta/batchattachRace
Open

Ensure PVCs are detached from VM only if VM spec does not have reference to them.#4003
skogta wants to merge 1 commit into
kubernetes-sigs:masterfrom
skogta:topic/skogta/batchattachRace

Conversation

@skogta
Copy link
Copy Markdown
Contributor

@skogta skogta commented Apr 30, 2026

What this PR does / why we need it:

During VM import, there is a race condition where there may be a delay from VM operator in adding a volume to batch attach spec.

In the meantime, CSI might incorrectly interpret that as a detach request (since volume is not there in batchattach spec but is attached to the VM on VM inventory).

In order to fix this, before adding a volume to detach list, it is important that CSI also validates that the volume is not being referenced in the VM spec. If it is being referenced, then skip adding that volume to detach list.

If VM object is not found, then fail the reconciliation.

As discussed on private chat, we should ignore safety check if PVC VM object is not found k8s cluster.

Testing done:
WCP precheckn (in progress): https://jenkins-vcf-csifvt.devops.broadcom.net/job/wcp-instapp-e2e-pre-checkin/1534/
VKS precheckin (in progress): https://jenkins-vcf-csifvt.devops.broadcom.net/job/vks-instapp-e2e-pre-checkin/1157/

Successfully attached a PVC to a VM.
Sucessfully detached a PVC from a VM.
Removed PVC from batchattach spec while it was still there in VM spec. Observed that detach was denied:

{"level":"info","time":"2026-04-30T09:17:44.95831583Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:257","msg":"Skipping detach for PVC test/pvc-3 with FCD 52c79ef3-affe-48f5-a295-317c324684c8 from VM Instance UUID 15294371-1935-4a95-96cb-56e2862bf2e2 because it is still referenced in VirtualMachine testvm-1 spec. This indicates the PVC is actively used by the VM.","TraceId":"461e96d0-df0c-4cc0-957f-515d9bce323a"}
{"level":"info","time":"2026-04-30T09:17:44.958387493Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:266","msg":"Obtained volumes to detach map[] for instance testvm-1","TraceId":"461e96d0-df0c-4cc0-957f-515d9bce323a"}

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 30, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: skogta
Once this PR has been reviewed and has the lgtm label, please assign xing-yang for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 30, 2026
@skogta skogta force-pushed the topic/skogta/batchattachRace branch 5 times, most recently from 9fd7f98 to a6f53f1 Compare April 30, 2026 08:30
@deepakkinni
Copy link
Copy Markdown
Collaborator

Triggering CSI-WCP Pre-checkin Pipeline for this PR... Job takes approximately an hour to complete
Jenkins Build #1365

@deepakkinni
Copy link
Copy Markdown
Collaborator

Triggering CSI-WCP Pre-checkin Pipeline for this PR... Job takes approximately an hour to complete
Jenkins Build #1366

@deepakkinni
Copy link
Copy Markdown
Collaborator

FAILED --- Jenkins Build #1365

@deepakkinni
Copy link
Copy Markdown
Collaborator

SUCCESS --- Jenkins Build #1366

@deepakkinni
Copy link
Copy Markdown
Collaborator

Triggering CSI-TKG Pre-checkin Pipeline for this PR... Job takes approximately an hour to complete
Jenkins Build #1084

@deepakkinni
Copy link
Copy Markdown
Collaborator

Triggering CSI-WCP Pre-checkin Pipeline for this PR... Job takes approximately an hour to complete
Jenkins Build #1368

@deepakkinni
Copy link
Copy Markdown
Collaborator

Triggering CSI-WCP Pre-checkin Pipeline for this PR... Job takes approximately an hour to complete
Jenkins Build #1369

@deepakkinni
Copy link
Copy Markdown
Collaborator

FAILED --- Jenkins Build #1369

@deepakkinni
Copy link
Copy Markdown
Collaborator

FAILED --- Jenkins Build #1368

@deepakkinni
Copy link
Copy Markdown
Collaborator

FAILED --- Jenkins Build #1084

@skogta skogta changed the title [WIP] validate fix Ensure PVCs are detached from VM only if VM spec does not have reference to them. Apr 30, 2026
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 30, 2026
@deepakkinni
Copy link
Copy Markdown
Collaborator

Triggering CSI-TKG Pre-checkin Pipeline for this PR... Job takes approximately an hour to complete
Jenkins Build #1087

@deepakkinni
Copy link
Copy Markdown
Collaborator

Triggering CSI-WCP Pre-checkin Pipeline for this PR... Job takes approximately an hour to complete
Jenkins Build #1371

@deepakkinni
Copy link
Copy Markdown
Collaborator

SUCCESS --- Jenkins Build #1087

@deepakkinni
Copy link
Copy Markdown
Collaborator

SUCCESS --- Jenkins Build #1371

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 6, 2026
@skogta skogta force-pushed the topic/skogta/batchattachRace branch from a6f53f1 to f939aee Compare May 20, 2026 14:27
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 20, 2026
@skogta skogta force-pushed the topic/skogta/batchattachRace branch from f939aee to 4a615a9 Compare May 20, 2026 14:29
@deepakkinni
Copy link
Copy Markdown
Collaborator

Triggering CSI-WCP Pre-checkin Pipeline for this PR... Job takes approximately an hour to complete
Jenkins Build #1534

@skogta skogta force-pushed the topic/skogta/batchattachRace branch from 4a615a9 to 6e6c8b3 Compare May 20, 2026 15:01
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@skogta: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-vsphere-csi-driver-verify-fmt 6e6c8b3 link true /test pull-vsphere-csi-driver-verify-fmt

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@deepakkinni
Copy link
Copy Markdown
Collaborator

Triggering CSI-TKG Pre-checkin Pipeline for this PR... Job takes approximately an hour to complete
Jenkins Build #1157

@deepakkinni
Copy link
Copy Markdown
Collaborator

FAILED --- Jenkins Build #1157

@deepakkinni
Copy link
Copy Markdown
Collaborator

SUCCESS --- Jenkins Build #1534

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants